package com.yt.product.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yt.common.constant.Result;
import com.yt.common.enums.CodeEnum;
import com.yt.product.models.bo.SupplierInfoBO;
import com.yt.product.models.dto.SupplierInfoDTO;
import com.yt.product.models.service.ISupplierInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 供应商信息控制器
 *
 * @author zhou
 * @Date 2025-09-05 11:31:21
 */

@RestController
@RequestMapping("/api/supplierInfo")
@Slf4j
@Api(value = "SupplierInfoApiController", tags = "供应商信息Api接口")
public class SupplierInfoApiController {

    @DubboReference
    private ISupplierInfoService supplierInfoService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找", notes = "根据id查找")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    public Result<SupplierInfoDTO> get(@RequestParam("id") Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }

        SupplierInfoDTO dto = supplierInfoService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "供应商信息列表", notes = "供应商信息列表")
    @PostMapping("/queryPageList")
    public Result<Page<SupplierInfoDTO>> queryPageList(SupplierInfoBO bo) {
        Wrapper<SupplierInfoDTO> wrapper = new EntityWrapper<>();
        if (bo.getStatus() != null) {
            wrapper.eq("status", bo.getStatus());
        }
        if (bo.getStartDate() != null) {
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null) {
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<SupplierInfoDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = supplierInfoService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
